package org.lanqiao.service.impl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.lanqiao.dao.IEleCoastDao;
import org.lanqiao.dao.IEleInfoDao;
import org.lanqiao.dao.IEleMindDao;
import org.lanqiao.dao.IEleOpeartorDao;
import org.lanqiao.myutil.Myutils;
import org.lanqiao.orm.EleCoast;
import org.lanqiao.orm.EleInfo;
import org.lanqiao.orm.EleMind;
import org.lanqiao.orm.EleOpeartor;
import org.lanqiao.service.IManagerFun;
import org.springframework.stereotype.Service;

@Service("ManagerService")
public class ManagerFun implements IManagerFun {

	@Resource
	IEleOpeartorDao opDao;

	@Resource
	IEleInfoDao infoDao;

	@Resource
	IEleMindDao mindDao;

	@Resource
	IEleCoastDao coastDao;
	@Override
	public boolean insertOp(EleOpeartor op) {
		// 插入成功返回true
		return opDao.insertOp(op) > 0 ? true : false;
	}

	@Override
	public boolean insertInfo(EleInfo info) {
		// 把信息存到数据库中
		return infoDao.insertInfo(info) > 0 ? true : false;
	}

	@Override
	public List selectAllInfo() {
		// 查询所有的信息
		return infoDao.selectAllInfo();
	}

	@Override
	public List<EleMind> selectMind() {
		// 查询最新一个月的建议和投诉信
		Date start = null;
		try {
			start = Myutils.getBeforeTime();
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return mindDao.selectMind(start);
	}

	@Override
	public List<EleMind> selectAllMind() {
		// 查询所有的信息
		return mindDao.selectAllMind();
	}
	@Override
	public List selectAllEleCoast(){
		//查询所有的电费价格
		List<EleCoast> listAll=coastDao.selectAllCoast();
		List all=new ArrayList();
		for (EleCoast ob : listAll) {
			List li=new ArrayList();
			li.add(Myutils.getTimeToString(ob.getCoastdate()));
			li.add(ob.getCoast());
			all.add(li);
		}
		return all;
	}

	@Override
	public boolean insertChange(String change) {
		//插入电费的变化信息
		return coastDao.insertChange(change)>0?true:false;
	}

}
